package com.zwr.sheller.customer.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.pojo.GoodsVo;
import com.zwr.sheller.core.util.ThreadLocalUtil;
import com.zwr.sheller.customer.Service.IndixService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 付龙江
 * @date 2022/1/6 14:21
 */
@RestController
@RequestMapping("/index")
@CrossOrigin
@Api(tags = "前台首页接口")
public class IndexController {

    @Autowired
    IndixService indixService;

    @PostMapping("/historyAndHot")
    @ApiOperation(value = "点击搜索后弹出的大家都在看/历史搜索记录")
    public Map<String,Object> historyAndHot(){
        Map<String, Object> map = indixService.selectHistoryAndHot();
        map.put("code",200);
        return map;
    }

    @PostMapping("/goodsSearch")
    @ApiOperation(value = "商品搜索")
    @ApiImplicitParam(name = "name", value = "请输入关键词搜索商品", required = true, dataType = "String", paramType = "query")
    public Map<String,Object> goodsSearch(String name) throws Exception {
        List<Map<String, Object>> list = indixService.searchGoods(name);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/myCity")
    @ApiOperation(value = "我的地址定位")
    @ApiImplicitParam(name = "city", value = "定位的城市名称（默认就是添加地址的城市，重新定位后就是新城市）", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> myCity(String city) throws Exception {
        String city1 = indixService.selectAddressCity(city);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("city",city1);
        return jsonResult.getMap();
    }



    @PostMapping("/indexBanner")
    @ApiOperation(value = "首页滚动的banner图片")
    public Map<String,Object> indexBanner(){
        Map<String,Object> map1 = new HashMap<>();
        map1.put("id","8168413929476227072");
        map1.put("img","http://47.108.60.93/ossImg/shopImg/4150caa47e11468cacff16ea0c0a3882.jpg");
        Map<String,Object> map2 = new HashMap<>();
        map2.put("id","8169531881841262592");
        map2.put("img","http://47.108.60.93/ossImg/shopImg/1feb69216023447b989cab0f1f301ef8.jpg");
        Map<String,Object> map3 = new HashMap<>();
        map3.put("id","8169568037305352192");
        map3.put("img","http://47.108.60.93/ossImg/shopImg/1cc9fde10e9447558c6a7a781bd0a5b0.jpg");
        Map<String,Object> map4 = new HashMap<>();
        map4.put("id","8169572002273198080");
        map4.put("img","http://47.108.60.93/ossImg/shopImg/f98c7db180924ac39dcdab0bef1c9cbf.jpg");
        List<Map<String,Object>> list = new ArrayList<>();
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }
    @PostMapping("selectByGoodsId")
    @ApiOperation(value = "商品一级分类，根据商品编号查简略信息，用于banner查")
    @ApiImplicitParam(name = "id", value = "商品id", required =true, dataType = "Long", paramType = "query")
    public Map<String,Object> selectByGoodsId(Long id) throws Exception {
        GoodsVo goodsVo = indixService.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",goodsVo);
        return jsonResult.getMap();
    }


    @PostMapping("/oneItemList")
    @ApiOperation(value = "商品一级分类(用于热买、新品、推荐商品上面的1级别分类)")
    public Map<String,Object> oneItemList(){
        List<String> list = new ArrayList<>();
        list.add("春季水果");
        list.add("夏季水果");
        list.add("秋季水果");
        list.add("冬季水果");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",list);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }



    @PostMapping("/hotGoods")
    @ApiOperation(value = "热销商品")
    @ApiImplicitParam(name = "typeName", value = "商品类型名称（不传就查询所有）", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> hotGoods(String typeName) throws Exception {
        List<Map<String, Object>> list = indixService.selectHotSales();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("storeTopGoods")
    @ApiOperation(value = "档口尖货")
    public Map<String,Object>storeTopGoods() throws Exception {
        List<Map<String, Object>> list = indixService.selectHotSales();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/newGoods")
    @ApiOperation(value = "新上商品")
    @ApiImplicitParam(name = "id", value = "商品类型的编号", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> newGoods(Long id) throws Exception {
        List<Map<String, Object>> list = indixService.selectHotSales();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/storeToRecommend")
    @ApiOperation(value = "掌柜推荐")
    @ApiImplicitParam(name = "typeName", value = "商品类型名称（不传默认为夏季水果）", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> storeToRecommend(String typeName){
        List<Map<String, Object>> list = indixService.selectGoodsIsRecommend(typeName);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/hotStore")
    @ApiOperation(value = "热门档口")
    public Map<String,Object> hotStore(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("hotStore","热门档口");
        return jsonResult.getMap();
    }

    @PostMapping("/newBanking")
    @ApiOperation(value = "最新冲榜")
    public Map<String,Object> newBanking(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("hotGoods","热销单品");
        jsonResult.setField("starStore","明星店铺");
        return jsonResult.getMap();
    }

    @PostMapping("/followStore")
    @ApiOperation(value = "关注店铺")
    @ApiImplicitParam(name = "id", value = "店铺的编号", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> followStore(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data","关注成功");
        return jsonResult.getMap();
    }

    @PostMapping("/everyDaySpecial")
    @ApiOperation(value = "天天特价")
    @ApiImplicitParam(name = "id", value = "商品类型的编号", required = false, dataType = "String", paramType = "query")
    public Map<String,Object> everyDaySpecial() throws Exception {
        List<Map<String, Object>> list = indixService.selectHotSales();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/goodsDetail")
    @ApiOperation(value = "商品详情")
    @ApiImplicitParam(name = "id", value = "商品编号", required = true, dataType = "Long", paramType = "query")
    public Map<String,Object> goodsDetail(Long id) throws Exception {
        Map<String, Object> map = indixService.selectByGoodsId(id);
        map.put("code","200");
        return map;
    }

}
